package com.sx.pipeline.utils

import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.View


/**
 * 作者　: hegaojian
 * 时间　: 2020/2/20
 * 描述　:项目中自定义类的拓展函数
 */


fun SpannableStringBuilder.setClickSpan(
    starIndex: Int,
    length: Int,
    textColor: Int? = null,
    clickCallBack: (() -> Unit?)? = null,
) {

    val clickSpan = object : ClickableSpan() {
        override fun onClick(widget: View) {
            clickCallBack?.invoke()
        }

        override fun updateDrawState(ds: TextPaint) {
            super.updateDrawState(ds)
            textColor?.let {
                ds.setColor(it)
            }
//            enableLine?.let {
//                ds.isUnderlineText = it
//            }
//            enableBold?.let {
//                ds.isFakeBoldText = it
//            }

        }

    }
    this.setSpan(clickSpan, starIndex, starIndex + length, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
}